<?php
use yii\helpers\Html;

/* @var $this \yii\web\View */
/* @var $content string */
?>

<header class="main-header">

    <?= Html::a('<span class="logo-mini">APP</span><span class="logo-lg">' . Yii::$app->name . '</span>', Yii::$app->homeUrl, ['class' => 'logo']) ?>

    <nav class="navbar navbar-static-top" role="navigation">

        <a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button">
            <span class="sr-only">Toggle navigation</span>
        </a>

        <div class="navbar-custom-menu">

            <ul class="nav navbar-nav">

                <!-- Messages: style can be found in dropdown.less-->
                <li class="dropdown user user-menu">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                        <i class="fa fa-refresh"></i>
                    </a>
                </li>
      
                <li class="dropdown user user-menu">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                        <img src="<?= $directoryAsset ?>/img/user2-160x160.jpg" class="user-image" alt="User Image"/>
                        <span class="hidden-xs">
                            <?php
                    if(Yii::$app->user->id > 0){
                        
                        
                    
                    $user = Yii::$app->runAction('user/get-user-info', ['id'=>  Yii::$app->user->id]);
                    
                    echo $user->username;
                    }else{
                        echo '游客';
                    }
                    ?>
                        </span>
                    </a>
          
                          
                    <ul class="dropdown-menu" style="width:220px;">
                        <!-- User image -->
                   
                        <!-- Menu Body -->
                     
                        <!-- Menu Footer-->
                        <li class="user-footer">
                          
                            <div class="pull-right">
                                 <?= Html::a(
                                    '修改密码',
                                    ['/user/update'],
                                    ['class' => 'btn btn-default btn-flat change-password','data-toggle'=>'modal','data-target'=>'#change-password']
                                ) ?>
                                
                                
                                <?= Html::a(
                                    '退出登录',
                                    ['/site/logout'],
                                    ['class' => 'btn btn-default btn-flat']
                                ) ?>
                            </div>
                        </li>
                    </ul>
                </li>

                <!-- User Account: style can be found in dropdown.less -->
                <li>
                    <a href="#" data-toggle="control-sidebar"><i class="fa fa-gears"></i></a>
                </li>
            </ul>
        </div>
    </nav>
</header>



<?php
    use yii\bootstrap\Modal;
    Modal::begin([
        'id' => 'change-password',
        'header' => '<h4 class="modal-title"></h4>',
        
    ]); 
    Modal::end();
    
    
    // 更新
$requestUpdateUrl = yii\helpers\Url::toRoute(['/user/update','id'=> Yii::$app->user->id]);
$js = <<<JS
    // 更新操作
    $('.change-password').on('click', function () {
        $('.modal-title').html('修改密码');
        //$.get('{$requestUpdateUrl}', { id: $(this).closest('tr').data('key') },
  
        $.get('{$requestUpdateUrl}', { id: $(this).parents("tr").children("td:eq(1)").html()},
            function (data) {
                $('.modal-body').html(data);
            }  
        );
    });
JS;
$this->registerJs($js);
?>



